this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,t,i,n,a,l,s,o,r,c,d){"use strict";var u;var g=function(e){babelHelpers.inherits(c,e);babelHelpers.createClass(c,null,[{key:"getInstance",value:function e(){if(!c.instance){c.instance=new c("landing_save_block_panel")}return c.instance}}]);function c(e,t){var i;babelHelpers.classCallCheck(this,c);t=t||{};t.title=a.Loc.getMessage("LANDING_SAVE_BLOCK_PANEL_TITLE_MSGVER_1");t.showFromRight=true;if(!t.block){return babelHelpers.possibleConstructorReturn(i)}i=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(c).call(this,e,t));babelHelpers.defineProperty(babelHelpers.assertThisInitialized(i),"cache",new d.Cache.MemoryCache);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(i),"bock",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(i),"previewFileIds",[]);i.block=t.block;i.mainInstance=l.Main.getInstance();d.Dom.addClass(i.layout,"landing-ui-panel-save-block");d.Dom.addClass(i.overlay,"landing-ui-panel-save-block");i.setButtons();i.renderTo(window.parent.document.body);return i}babelHelpers.createClass(c,[{key:"setButtons",value:function e(){this.appendFooterButton(new BX.Landing.UI.Button.BaseButton("save_block_content",{text:a.Loc.getMessage("BLOCK_SAVE"),onClick:this.onSave.bind(this),className:"landing-ui-button-content-save"}));this.appendFooterButton(new BX.Landing.UI.Button.BaseButton("cancel_block_content",{text:a.Loc.getMessage("BLOCK_CANCEL"),onClick:this.hide.bind(this),className:"landing-ui-button-content-cancel"}))}},{key:"getTitleField",value:function e(){return this.cache.remember("titleField",(function(){return new r.TextField({title:a.Loc.getMessage("LANDING_SAVE_BLOCK_PANEL_FIELD_TITLE"),textOnly:true})}))}},{key:"getSectionsField",value:function e(){return this.cache.remember("sectionsField",(function(){var e=[];var t=i.Env.getInstance().getOptions(),n=t.blocks;Object.keys(n).map((function(t){if(t!=="last"&&t!=="separator_apps"&&t.indexOf(".")===-1){e.push({value:t,name:n[t].name})}}));return new BX.Landing.UI.Field.MultiSelect({title:a.Loc.getMessage("LANDING_SAVE_BLOCK_PANEL_FIELD_SECTIONS"),items:e})}))}},{key:"getTemplateRefField",value:function e(){return this.cache.remember("templateRefField",(function(){return new BX.Landing.UI.Field.Checkbox({items:[{value:"N",name:a.Loc.getMessage("LANDING_SAVE_BLOCK_PANEL_FIELD_TEMPLATE_REF")}]})}))}},{key:"getPreviewField",value:function e(){var t=this;return this.cache.remember("preview",(function(){return new BX.Landing.UI.Field.Image({title:a.Loc.getMessage("LANDING_SAVE_BLOCK_PANEL_FIELD_PREVIEW"),disableLink:true,disableAltField:true,uploadParams:{action:"Block::uploadFile",block:t.block.id},content:{src:"/bitrix/images/1.gif",id:-1,alt:""},dimensions:{width:1200,height:600}})}))}},{key:"getMessage",value:function e(){return this.cache.remember("message",(function(){return new o.MessageCard({id:"fieldsMessage",header:a.Loc.getMessage("LANDING_SAVE_BLOCK_PANEL_MESSAGE_TITLE_MSGVER_1"),description:a.Loc.getMessage("LANDING_SAVE_BLOCK_PANEL_MESSAGE_TEXT_MSGVER_1"),restoreState:true})}))}},{key:"getForm",value:function e(){var t=this;return this.cache.remember("form",(function(){return new BX.Landing.UI.Form.BaseForm({fields:[t.getTitleField(),t.getSectionsField(),t.mainInstance.getTemplateCode()?t.getTemplateRefField():null,t.getPreviewField()]})}))}},{key:"makeScreenshot",value:function e(){var i=this;this.getPreviewField().showLoader();void s.Screenshoter.makeBlockScreenshot(this.block.id).then((function(e){return n.ImageCompressor.compress(e,{maxWidth:830,maxHeight:300})})).then((function(e){return t.Backend.getInstance().upload(e,{block:i.block.id,temp:true})})).then((function(e){i.getPreviewField().setValue(e);i.getPreviewField().hideLoader()}))}},{key:"show",value:function e(t){var i,n,a,l,s,o,r,u,g,h,v;d.Dom.style(this.footer,"display",null);this.getTitleField().setValue((i=this.block)===null||i===void 0?void 0:(n=i.manifest)===null||n===void 0?void 0:(a=n.block)===null||a===void 0?void 0:a.name);this.getSectionsField().setValue(((l=this.block)===null||l===void 0?void 0:(s=l.manifest)===null||s===void 0?void 0:(o=s.block)===null||o===void 0?void 0:o.section)||[]);this.getTemplateRefField().setValue(["Y"]);this.getPreviewField().setValue({src:((r=this.block)===null||r===void 0?void 0:(u=r.manifest)===null||u===void 0?void 0:u.preview)||((g=this.block)===null||g===void 0?void 0:(h=g.manifest)===null||h===void 0?void 0:(v=h.block)===null||v===void 0?void 0:v.preview)||""});this.makeScreenshot();this.clear();d.Dom.prepend(this.getMessage().getLayout(),this.content);this.appendForm(this.getForm());return babelHelpers.get(babelHelpers.getPrototypeOf(c.prototype),"show",this).call(this)}},{key:"getFailMessage",value:function e(){return this.cache.remember("failMessage",(function(){return d.Tag.render(u||(u=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-panel-save-block-fail">\n\t\t\t\t\t<div class="landing-ui-panel-save-block-fail-header">\n\t\t\t\t\t\t',"\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t"])),a.Loc.getMessage("LANDING_SAVE_BLOCK_PANEL_FAIL_MESSAGE_TITLE"))}))}},{key:"onSave",value:function e(){var i,n,l=this;var s=t.Backend.getInstance();var o=this.getTitleField().getValue();var r=this.getTemplateRefField().getValue().length>0;var c=this.getPreviewField().getValue();var u=(i=this.block)===null||i===void 0?void 0:(n=i.manifest)===null||n===void 0?void 0:n.code;var g=this.getSectionsField().getValue();this.clear();this.hide();if(!u){return}s.action("Landing::favoriteBlock",{lid:this.block.lid,block:this.block.id,meta:{name:o,section:g,preview:Math.max(c.id,0),tpl_code:r?this.mainInstance.getTemplateCode():null}},{code:u}).then((function(e){if(e){top.BX.UI.Notification.Center.notify({content:a.Loc.getMessage("LANDING_SAVE_BLOCK_PANEL_SUCCESS")});g.push("last");g.map((function(t){l.mainInstance.addNewBlockToCategory(t,{code:u,codeOriginal:u+"@"+e,name:o,preview:c.src,section:g,favorite:true,favoriteMy:true,repo_id:l.block.repoId})}))}else{d.Dom.append(l.getFailMessage(),l.content)}}))}}]);return c}(c.Content);e.SaveBlock=g})(this.BX.Landing.UI.Panel=this.BX.Landing.UI.Panel||{},BX.Landing,BX.Landing,BX.Landing,BX.Landing,BX.Landing,BX.Landing,BX.Landing.UI.Card,BX.Landing.UI.Field,BX.Landing.UI.Panel,BX);
//# sourceMappingURL=saveblock.bundle.map.js